<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in titles"
      :key="index"
      @click="itemClick(item.sort)"
      class="tab-item"
      :class="{ active: item.sort === currentType }"
    >
      <span>{{ item.title }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControll",
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentType: 'pop',
    };
  },
  methods: {
    itemClick(type) {
      this.currentType = type;
      //给父组件传递当前tab类型
      this.$emit('tabCick', type)
    },
  },
};
</script>
<style scoped>
.tab-control {
  display: flex;
  text-align: center;
  font-weight: bold;
  font-size: 16px;
  line-height: 40px;
  height: 40px;
  background: white;
}
.tab-item {
  flex: 1;
}
.tab-item span {
  padding: 5px;
}
.active span {
  border-bottom: 3px solid #f56ea2;
  color: #f56ea2;
}
</style>